package net.jiupinshi.dao;


import net.jiupinshi.daoProvider.StoreProvider;
import net.jiupinshi.dto.StoreSimpleDTO;
import net.jiupinshi.entity.Store;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Despription: 需要修改
 * @Author: penghui.guo
 * @Date: 2018/10/5 15:19
 */
public interface StoreDao {

    @Insert("insert into store(user_id, user_name, name, phone, address, remark) values (#{userId}," +
            "#{userName},#{name},#{phone},#{address},#{remark})")
    @Options(useGeneratedKeys = true)
    int insertStore(Store store);

    @UpdateProvider(type = StoreProvider.class, method = "updateStoreById")
    int updateStoreById(Store store);

    @SelectProvider(type = StoreProvider.class, method = "getStores")
    List<StoreSimpleDTO> getStores();

    @Select("select id, user_id as userId, name, user_name as userName from store where id = #{id}")
    Store getStoreById(Long id);

    @Select("select s.id, s.user_id as userId, s.name, s.user_name as userName from store s, " +
            "store_user_relation sur where sur.user_id = #{uid} and sur.store_id = s.id")
    Store getStoreByIRelationUd(Long uid);

    @Select("select id, user_id as userId, name, user_name as userName from store where user_id = #{uid}")
    Store getStoreByUid(Long uid);

}
